<?php
namespace app\common\model;

use think\Model;

/**
 * orders 订单表
 * 赵振远 2017.12.22 暂时
 * @package app\common\model
 */
class Orders extends Model
{
    //自动转换时间戳
    protected $type = [
        'ord_create_time' => 'timestamp:Y-m-d H:i:s',
    ];

    //自动转换状态
    public function getOrdStatusAttr($value)
    {
        // 0未付款1付款
        $ord_status = [-1 => '未付款', 1 => '已付款'];
        return $ord_status[$value];
    }

    //设置主键
    protected $pk = 'ord_id';
    //关联用户
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id')->field('id');
    }

    //一对多
    public function shops()
    {
        return $this->belongsTo('Shops', 'ord_shop_id', 'sp_id')->field('sp_id,sp_name,sp_logo_url');
    }

    public function coupons()
    {
        return $this->hasMany('Coupons', 'cou_id', 'coup_id')->field('sp_name');
    }

    public function orderShops(){
        $res1= $this->hasMany('Shops','ord_shop_id','sp_id')->field('sp_id,sp_name');

        return $res1;
    }

}
